package com.cs.archivesmanagement.action;

import com.cs.archivesmanagement.entity.AmArchivesRequests;
import com.cs.archivesmanagement.entity.AmDepartment;
import com.cs.archivesmanagement.entity.AmFileType;
import com.cs.archivesmanagement.service.AccountService;
import com.cs.archivesmanagement.service.ArchivesDealWithService;
import com.cs.archivesmanagement.service.ArchivesService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.io.*;
import java.util.ArrayList;

/**
 * Created by amo on 2015/8/25.
 */

@Controller
@Namespace("/")
@Results({@Result(name = "upLoadSuccess", location = "/uploadresult.jsp"),
        @Result(name = "dealaddarvhivepage",location ="/fileManager/deladdarchive.jsp"),
        @Result(name = "adddetailpage",location ="/fileManager/addarchivedealdetail.jsp"),
        @Result(name ="modified",location ="/fileManager/deladdarchive.jsp"),
        @Result(name = "dealgetarchivespage",location = "/fileManager/dealgetarchives.jsp"),
        @Result(name = "getModify",location = "/fileManager/dealgetarchives.jsp"),
        @Result(name = "archivesdetail",location = "/fileManager/archivedealdetail.jsp"),
        @Result(name = "logpage",location = "/systemManager/log.jsp"),
        @Result(name = "rollback",location = "/systemManager/log.jsp"),
        @Result(name = "dealdelarvhivepage",location = "/fileManager/deldeletearchive.jsp")




}


)
public class ArchivesDealWithAction extends ActionSupport {

        @Resource
        ArchivesDealWithService archivesDealWithService;


@Resource
    AccountService accountService;

    @Resource
    ArchivesService archivesService;




        ArrayList<AmArchivesRequests> amArchivesRequestsArrayList;

    ArrayList<AmDepartment> amDepartmentArrayList;

    ArrayList<AmFileType> amFileTypeArrayList;

        Integer approvalerId;


    AmArchivesRequests amArchivesRequests;


    Integer amArchivesRequestsId;

    Integer operateCode;

    Integer isAgressOrDenied;

        @org.apache.struts2.convention.annotation.Action("dealaddarchive")
        public String dealWithAddArchive(){

            amDepartmentArrayList=accountService.getAllAmDepartment();
            amFileTypeArrayList=archivesService.getAllFileType();

           amArchivesRequestsArrayList=archivesDealWithService.getAllAmArchivesRequestsByParameter(AmArchivesRequests.archivesRequestsType_add, null, AmArchivesRequests.archivesRequestsStatus_pending);


            System.out.println("等待审核的增加档案有:"+amArchivesRequestsArrayList.size());
            return  "dealaddarvhivepage";

        }

    @org.apache.struts2.convention.annotation.Action("dealdelarchive")
    public String dealWithDelArchive(){

        amDepartmentArrayList=accountService.getAllAmDepartment();
        amFileTypeArrayList=archivesService.getAllFileType();

        amArchivesRequestsArrayList=archivesDealWithService.getAllAmArchivesRequestsByParameter(AmArchivesRequests.archivesRequestsType_delete, null, AmArchivesRequests.archivesRequestsStatus_pending);

        System.out.println("等待删除的档案有:"+amArchivesRequestsArrayList.size());
        return  "dealdelarvhivepage";

    }
    @org.apache.struts2.convention.annotation.Action("addardetail")
    public String addFileDetail(){


       System.out.println("进入到增加审批详细页面，审核者是"+approvalerId+"请求"+amArchivesRequestsId);

       amArchivesRequests=archivesDealWithService.findById(amArchivesRequestsId);

          return "adddetailpage";

    }

    @org.apache.struts2.convention.annotation.Action("archivesdetail")
    public String archiveDetail(){


        System.out.println("进入到档案详细页面，请求"+amArchivesRequestsId);

        amArchivesRequests=archivesDealWithService.findById(amArchivesRequestsId);

        return "archivesdetail";


    }


    @org.apache.struts2.convention.annotation.Action("dealgetarchives")
    public String dealGetArchvive(){

        amDepartmentArrayList=accountService.getAllAmDepartment();
        amFileTypeArrayList=archivesService.getAllFileType();

        amArchivesRequestsArrayList=archivesDealWithService.getAllAmArchivesRequestsByParameter(AmArchivesRequests.archivesRequestsType_get, null, AmArchivesRequests.archivesRequestsStatus_pending);


        System.out.println("等待借阅的档案有:"+amArchivesRequestsArrayList.size());



        return "dealgetarchivespage";
    }


    @org.apache.struts2.convention.annotation.Action("pageModify")
    public  String PageModify(){


        System.out.println("审核页面修改,审核者是"+approvalerId+"请求"+amArchivesRequestsId);

        archivesDealWithService.dealWithRequest(amArchivesRequestsId,isAgressOrDenied==1,approvalerId);

        amDepartmentArrayList=accountService.getAllAmDepartment();
        amFileTypeArrayList=archivesService.getAllFileType();

        amArchivesRequestsArrayList=archivesDealWithService.getAllAmArchivesRequestsByParameter(AmArchivesRequests.archivesRequestsType_add, null, AmArchivesRequests.archivesRequestsStatus_pending);

        return "modified";

   }

    @org.apache.struts2.convention.annotation.Action("pagemodifyget")

    public String PageModifyGet(){


        System.out.println("审核页面修改,审核者是"+approvalerId+"请求"+amArchivesRequestsId);

        archivesDealWithService.dealWithRequest(amArchivesRequestsId,isAgressOrDenied==1,approvalerId);

        amDepartmentArrayList=accountService.getAllAmDepartment();
        amFileTypeArrayList=archivesService.getAllFileType();

        amArchivesRequestsArrayList=archivesDealWithService.getAllAmArchivesRequestsByParameter(AmArchivesRequests.archivesRequestsType_get, null, AmArchivesRequests.archivesRequestsStatus_pending);

        return "getModify";
    }

    @org.apache.struts2.convention.annotation.Action("logpage")

    public String logPage(){

     amArchivesRequestsArrayList=archivesDealWithService.getAllAmArchivesRequestsByParameter(null,null,null);

        return "logpage";

    }

    @org.apache.struts2.convention.annotation.Action("rollback")

    public String rollBack(){

        System.out.println("回滚action:"+amArchivesRequestsId);
        archivesDealWithService.rollBackRequest(amArchivesRequestsId);

        return  "rollback";

    }

    public ArchivesDealWithService getArchivesDealWithService() {
        return archivesDealWithService;
    }

    public ArrayList<AmArchivesRequests> getAmArchivesRequestsArrayList() {
        return amArchivesRequestsArrayList;
    }

    public void setAmArchivesRequestsArrayList(ArrayList<AmArchivesRequests> amArchivesRequestsArrayList) {
        this.amArchivesRequestsArrayList = amArchivesRequestsArrayList;
    }

    public void setApprovalerId(Integer approvalerId) {
        this.approvalerId = approvalerId;
    }


    public ArrayList<AmFileType> getAmFileTypeArrayList() {
        return amFileTypeArrayList;
    }

    public ArrayList<AmDepartment> getAmDepartmentArrayList() {
        return amDepartmentArrayList;
    }

    public void setAmFileTypeArrayList(ArrayList<AmFileType> amFileTypeArrayList) {
        this.amFileTypeArrayList = amFileTypeArrayList;
    }

    public void setAmDepartmentArrayList(ArrayList<AmDepartment> amDepartmentArrayList) {
        this.amDepartmentArrayList = amDepartmentArrayList;
    }

    public AccountService getAccountService() {
        return accountService;
    }

    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }

    public AmArchivesRequests getAmArchivesRequests() {
        return amArchivesRequests;
    }

    public Integer getAmArchivesRequestsId() {
        return amArchivesRequestsId;
    }

    public Integer getApprovalerId() {
        return approvalerId;
    }

    public void setAmArchivesRequests(AmArchivesRequests amArchivesRequests) {
        this.amArchivesRequests = amArchivesRequests;
    }

    public void setAmArchivesRequestsId(Integer amArchivesRequestsId) {
        this.amArchivesRequestsId = amArchivesRequestsId;
    }

    public ArchivesService getArchivesService() {
        return archivesService;
    }

    public Integer getIsAgressOrDenied() {
        return isAgressOrDenied;
    }

    public void setArchivesDealWithService(ArchivesDealWithService archivesDealWithService) {
        this.archivesDealWithService = archivesDealWithService;
    }

    public void setIsAgressOrDenied(Integer isAgressOrDenied) {
        this.isAgressOrDenied = isAgressOrDenied;
    }

    public void setOperateCode(Integer operateCode) {
        this.operateCode = operateCode;
    }
}

